<template>
  <div>
    <div v-loading="loading">
     
      <el-table :data="tableData" border style="width: 100%" @selection-change="handleSelectionChange" >
        <el-table-column prop="name" label="序号" width="60">
          <template slot-scope="scope">{{scope.$index+1}}</template>
        </el-table-column>
        <el-table-column prop="createtime" label="注册时间" width="100">
          <template slot-scope="scope">{{timeFun(scope.row.createtime)}}</template>
        </el-table-column>      
        <el-table-column prop="userPhone" label="账号"></el-table-column>
        <el-table-column prop="userNick" label="昵称">
          <template slot-scope="scope">
            <span>{{scope.row.userNick}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="dynamicNumber" label="文章" width="100"></el-table-column>
        <el-table-column prop="fansNumber" label="粉丝" width="100"></el-table-column>
        <el-table-column prop="edit" label="状态" width="100">
          userStatus
          <template slot-scope="scope">
            <span v-if="scope.row.userStatus==1">启用</span>
            <span v-else style="color:red">隐藏</span>
          </template>
        </el-table-column>

        <el-table-column width="160" label="操作">
          <template slot-scope="scope">
            <div>
              <el-button class="addBtn" type="primary" @click="editUserTitle(scope.row)">编辑</el-button>
              <el-button class="addBtn" v-if="scope.row.userStatus==1" type="danger" @click="deletData(scope.row)"> 隐藏</el-button>
              <el-button class="addBtn" v-else type="success" @click="enableUser(scope.row)"> 启用</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
   
    </div>

    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>

   
   <AddCuser v-if="dialogPipo" ref="adduser" :dialogPipo="dialogPipo" :userdata="userdata" @showFun ="closePipo"></AddCuser>
   
  </div>
</template>

<script>
  import AddCuser from './AddCuser'
  import Http from '@/Http/Http'
  import getTime from '@/Http/getTime'
  export default {
    data() {
      return {
        adduserSta:false,
        dialogPipo:false,
        loading:false,
        userdata:'',//编辑字段
        tableData: [],
        total:0,
        currentPage4: 1,//分野
        pageIndex:1,
        pageSize:10,
      }
    },
    components:{
      AddCuser
    },
    created() {
      this.getCuser()
    },
    methods: {
      getCuser(){
        this.loading = true;

        Http.getUserlist({
          "pageIndex":this.pageIndex,
          "pageSize":this.pageSize,
          "role":2,
        })
        .then( res => {
          this.loading = false;
          this.tableData  = res.data.data.rows;
          this.total = res.data.data.total
        })
        .catch( error => {
          this.loading = false;
        })
      },
      
      timeFun(val) {
        return getTime(val)
      },
      
     
       getdata (evt) {
        },
        datadragEnd (evt) {
            evt.preventDefault();
          
        },
      editUserTitle(row){
        this.userdata = row;
        this.dialogPipo = true;
      },
      deletData(row) {
        this.$confirm('确定隐藏此用户吗？','提示',{
          confirmVuttonText:'确定',
          confirmButtonText:'确定'
        }).then( ()=> {
          
          Http.stopUser(row.userId)
          .then(res => {
            if(res.data.code == 200 ) { 
              this.$message.success('用户隐藏成功')
              this.getCuser()
            }
          })
        }).catch( ()=> {
          
        })
      },
      
      enableUser(row) { 
        this.$confirm('确定启用此用户吗？','提示',{
          confirmVuttonText:'确定',
          confirmButtonText:'确定'
        }).then( ()=> {
          
          Http.startUser(row.userId)
          .then(res => {
            if(res.data.code == 200 ) { 
              this.$message.success('用户启用成功')
              this.getCuser()
            }
          })
        }).catch( ()=> {
          
        })
      },


      chageStatus(val) {
        let txt ='';
        val? txt ='开启' : txt = '关闭';
       
        
      },
      //添加用户
       //添加用户
     
      addCpipoFun() {
        this.dialogPipo = true;
        this.adduserSta = true;
      },
     
      closePipo() {
        this.dialogPipo = false;
        this.adduserSta = false;
        this.getCuser()
      },
      //选择 推荐
      handleSelectionChange() {
        
      },
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      },
    
       //分页
      handleSizeChange(val) {
        this.pageSize = val;
        this.getCuser()
        
      },
      handleCurrentChange(val) {
        this.pageIndex = val;
        this.getCuser()
        
      },
    }
  }
</script>
<style  scoped>
.box{
  border-bottom:1px solid red;
}
    .test{
        border:1px solid #ccc;
    }
    .drag-item{
        width: 200px;
        height: 50px;
        line-height: 50px;
        margin: auto;
        position: relative;
        
        background: #ddd;
        margin:20px 5px;
    }
    .ghostClass{
        opacity: 1;
    }
    .bottom{
        width: 200px;
        height: 50px;
        position: relative;
        background: blue;
        top:2px; 
        left: 2px;
        transition: all .5s linear;
    }
</style>
